import { REMOVE_FILES, SET_FILES } from '../constant';
import { DIRECTORIES, FILES } from '../../constant';

export const setFiles = (data) => {
  let dir = data[DIRECTORIES]
  let normalFile = data[FILES]
  let flag = true
  let checkedCount = 0
  if (dir) {
    for (let i = 0; i < dir.length; i++) {
      if (!dir[i].checked) {
        flag = false
        continue
      }
      checkedCount++;
    }
  }
  if (normalFile) {
    for (let i = 0; i < normalFile.length; i++) {
      if (!normalFile[i].checked) {
        flag = false
        continue
      }
      checkedCount++;
    }
  }
  data.checkedAll = flag && checkedCount !== 0;
  data.checkedCount = checkedCount
  return ({
    type: SET_FILES, data
  })
}

export const removeFiles = () => ({ type: REMOVE_FILES })

